\hypertarget{group__mpu__api}{
\section{Mpu\_\-api}
\label{group__mpu__api}\index{Mpu\_\-api@{Mpu\_\-api}}
}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
void \hyperlink{group__mpu__api_gaba9eff5d850faff33526161e431822a2}{MPUEnable} (unsigned long ulMPUConfig)
\item 
void \hyperlink{group__mpu__api_gae98f222992a05f9a0feae96f933dd69d}{MPUDisable} (void)
\item 
unsigned long \hyperlink{group__mpu__api_ga2913870e26a377e1407e1c87ba2c7021}{MPURegionCountGet} (void)
\item 
void \hyperlink{group__mpu__api_ga2c74fe6aece0858f6610424e9610b18c}{MPURegionEnable} (unsigned long ulRegion)
\item 
void \hyperlink{group__mpu__api_gab8dbf14069e23e2ec1254d5825688bc7}{MPURegionDisable} (unsigned long ulRegion)
\item 
void \hyperlink{group__mpu__api_ga6b5ebdb618cd71191b07b3d3abcdfe4b}{MPURegionSet} (unsigned long ulRegion, unsigned long ulAddr, unsigned long ulFlags)
\item 
void \hyperlink{group__mpu__api_gabb00a8e0bb445ff6f7276ebc5d0b4a73}{MPURegionGet} (unsigned long ulRegion, unsigned long $\ast$pulAddr, unsigned long $\ast$pulFlags)
\item 
void \hyperlink{group__mpu__api_ga5f391e2bed9919c3e98ee744d76a5a03}{MPUIntRegister} (void($\ast$pfnHandler)(void))
\item 
void \hyperlink{group__mpu__api_ga8bd36f9796c8a112476a11f381cd5c90}{MPUIntUnregister} (void)
\end{DoxyCompactItemize}


\subsection{Function Documentation}
\hypertarget{group__mpu__api_gae98f222992a05f9a0feae96f933dd69d}{
\index{mpu\_\-api@{mpu\_\-api}!MPUDisable@{MPUDisable}}
\index{MPUDisable@{MPUDisable}!mpu_api@{mpu\_\-api}}
\subsubsection[{MPUDisable}]{\setlength{\rightskip}{0pt plus 5cm}void MPUDisable (
\begin{DoxyParamCaption}
\item[{void}]{}
\end{DoxyParamCaption}
)}}
\label{group__mpu__api_gae98f222992a05f9a0feae96f933dd69d}
Disables the MPU for use.

This function disables the Cortex-\/M3 memory protection unit. When the MPU is disabled, the default memory map is used and memory management faults are not generated.

\begin{DoxyReturn}{Returns}
None. 
\end{DoxyReturn}
\hypertarget{group__mpu__api_gaba9eff5d850faff33526161e431822a2}{
\index{mpu\_\-api@{mpu\_\-api}!MPUEnable@{MPUEnable}}
\index{MPUEnable@{MPUEnable}!mpu_api@{mpu\_\-api}}
\subsubsection[{MPUEnable}]{\setlength{\rightskip}{0pt plus 5cm}void MPUEnable (
\begin{DoxyParamCaption}
\item[{unsigned long}]{ ulMPUConfig}
\end{DoxyParamCaption}
)}}
\label{group__mpu__api_gaba9eff5d850faff33526161e431822a2}
Enables and configures the MPU for use.


\begin{DoxyParams}{Parameters}
\item[{\em ulMPUConfig}]is the logical OR of the possible configurations.\end{DoxyParams}
This function enables the Cortex-\/M3 memory protection unit. It also configures the default behavior when in privileged mode and while handling a hard fault or NMI. Prior to enabling the MPU, at least one region must be set by calling \hyperlink{group__mpu__api_ga6b5ebdb618cd71191b07b3d3abcdfe4b}{MPURegionSet()} or else by enabling the default region for privileged mode by passing the {\bfseries MPU\_\-CONFIG\_\-PRIV\_\-DEFAULT} flag to \hyperlink{group__mpu__api_gaba9eff5d850faff33526161e431822a2}{MPUEnable()}. Once the MPU is enabled, a memory management fault will be generated for any memory access violations.

The {\itshape ulMPUConfig\/} parameter should be the logical OR of any of the following:


\begin{DoxyItemize}
\item {\bfseries MPU\_\-CONFIG\_\-PRIV\_\-DEFAULT} enables the default memory map when in privileged mode and when no other regions are defined. If this option is not enabled, then there must be at least one valid region already defined when the MPU is enabled.
\item {\bfseries MPU\_\-CONFIG\_\-HARDFLT\_\-NMI} enables the MPU while in a hard fault or NMI exception handler. If this option is not enabled, then the MPU is disabled while in one of these exception handlers and the default memory map is applied.
\item {\bfseries MPU\_\-CONFIG\_\-NONE} chooses none of the above options. In this case, no default memory map is provided in privileged mode, and the MPU will not be enabled in the fault handlers.
\end{DoxyItemize}

\begin{DoxyReturn}{Returns}
None. 
\end{DoxyReturn}
\hypertarget{group__mpu__api_ga5f391e2bed9919c3e98ee744d76a5a03}{
\index{mpu\_\-api@{mpu\_\-api}!MPUIntRegister@{MPUIntRegister}}
\index{MPUIntRegister@{MPUIntRegister}!mpu_api@{mpu\_\-api}}
\subsubsection[{MPUIntRegister}]{\setlength{\rightskip}{0pt plus 5cm}void MPUIntRegister (
\begin{DoxyParamCaption}
\item[{void($\ast$)(void)}]{ pfnHandler}
\end{DoxyParamCaption}
)}}
\label{group__mpu__api_ga5f391e2bed9919c3e98ee744d76a5a03}
Registers an interrupt handler for the memory management fault.


\begin{DoxyParams}{Parameters}
\item[{\em pfnHandler}]is a pointer to the function to be called when the memory management fault occurs.\end{DoxyParams}
This sets and enables the handler to be called when the MPU generates a memory management fault due to a protection region access violation.

\begin{DoxySeeAlso}{See also}
\hyperlink{group__interrupt__api_ga471d00d73ae22faa426c202f608e9c69}{IntRegister()} for important information about registering interrupt handlers.
\end{DoxySeeAlso}
\begin{DoxyReturn}{Returns}
None. 
\end{DoxyReturn}
\hypertarget{group__mpu__api_ga8bd36f9796c8a112476a11f381cd5c90}{
\index{mpu\_\-api@{mpu\_\-api}!MPUIntUnregister@{MPUIntUnregister}}
\index{MPUIntUnregister@{MPUIntUnregister}!mpu_api@{mpu\_\-api}}
\subsubsection[{MPUIntUnregister}]{\setlength{\rightskip}{0pt plus 5cm}void MPUIntUnregister (
\begin{DoxyParamCaption}
\item[{void}]{}
\end{DoxyParamCaption}
)}}
\label{group__mpu__api_ga8bd36f9796c8a112476a11f381cd5c90}
Unregisters an interrupt handler for the memory management fault.

This function will disable and clear the handler to be called when a memory management fault occurs.

\begin{DoxySeeAlso}{See also}
\hyperlink{group__interrupt__api_ga471d00d73ae22faa426c202f608e9c69}{IntRegister()} for important information about registering interrupt handlers.
\end{DoxySeeAlso}
\begin{DoxyReturn}{Returns}
None. 
\end{DoxyReturn}
\hypertarget{group__mpu__api_ga2913870e26a377e1407e1c87ba2c7021}{
\index{mpu\_\-api@{mpu\_\-api}!MPURegionCountGet@{MPURegionCountGet}}
\index{MPURegionCountGet@{MPURegionCountGet}!mpu_api@{mpu\_\-api}}
\subsubsection[{MPURegionCountGet}]{\setlength{\rightskip}{0pt plus 5cm}unsigned long MPURegionCountGet (
\begin{DoxyParamCaption}
\item[{void}]{}
\end{DoxyParamCaption}
)}}
\label{group__mpu__api_ga2913870e26a377e1407e1c87ba2c7021}
Gets the count of regions supported by the MPU.

This function is used to get the number of regions that are supported by the MPU. This is the total number that are supported, including regions that are already programmed.

\begin{DoxyReturn}{Returns}
The number of memory protection regions that are available for programming using \hyperlink{group__mpu__api_ga6b5ebdb618cd71191b07b3d3abcdfe4b}{MPURegionSet()}. 
\end{DoxyReturn}
\hypertarget{group__mpu__api_gab8dbf14069e23e2ec1254d5825688bc7}{
\index{mpu\_\-api@{mpu\_\-api}!MPURegionDisable@{MPURegionDisable}}
\index{MPURegionDisable@{MPURegionDisable}!mpu_api@{mpu\_\-api}}
\subsubsection[{MPURegionDisable}]{\setlength{\rightskip}{0pt plus 5cm}void MPURegionDisable (
\begin{DoxyParamCaption}
\item[{unsigned long}]{ ulRegion}
\end{DoxyParamCaption}
)}}
\label{group__mpu__api_gab8dbf14069e23e2ec1254d5825688bc7}
Disables a specific region.


\begin{DoxyParams}{Parameters}
\item[{\em ulRegion}]is the region number to disable.\end{DoxyParams}
This function is used to disable a previously enabled memory protection region. The region will remain configured if it is not overwritten with another call to \hyperlink{group__mpu__api_ga6b5ebdb618cd71191b07b3d3abcdfe4b}{MPURegionSet()}, and can be enabled again by calling \hyperlink{group__mpu__api_ga2c74fe6aece0858f6610424e9610b18c}{MPURegionEnable()}.

\begin{DoxyReturn}{Returns}
None. 
\end{DoxyReturn}
\hypertarget{group__mpu__api_ga2c74fe6aece0858f6610424e9610b18c}{
\index{mpu\_\-api@{mpu\_\-api}!MPURegionEnable@{MPURegionEnable}}
\index{MPURegionEnable@{MPURegionEnable}!mpu_api@{mpu\_\-api}}
\subsubsection[{MPURegionEnable}]{\setlength{\rightskip}{0pt plus 5cm}void MPURegionEnable (
\begin{DoxyParamCaption}
\item[{unsigned long}]{ ulRegion}
\end{DoxyParamCaption}
)}}
\label{group__mpu__api_ga2c74fe6aece0858f6610424e9610b18c}
Enables a specific region.


\begin{DoxyParams}{Parameters}
\item[{\em ulRegion}]is the region number to enable.\end{DoxyParams}
This function is used to enable a memory protection region. The region should already be set up with the \hyperlink{group__mpu__api_ga6b5ebdb618cd71191b07b3d3abcdfe4b}{MPURegionSet()} function. Once enabled, the memory protection rules of the region will be applied and access violations will cause a memory management fault.

\begin{DoxyReturn}{Returns}
None. 
\end{DoxyReturn}
\hypertarget{group__mpu__api_gabb00a8e0bb445ff6f7276ebc5d0b4a73}{
\index{mpu\_\-api@{mpu\_\-api}!MPURegionGet@{MPURegionGet}}
\index{MPURegionGet@{MPURegionGet}!mpu_api@{mpu\_\-api}}
\subsubsection[{MPURegionGet}]{\setlength{\rightskip}{0pt plus 5cm}void MPURegionGet (
\begin{DoxyParamCaption}
\item[{unsigned long}]{ ulRegion, }
\item[{unsigned long $\ast$}]{ pulAddr, }
\item[{unsigned long $\ast$}]{ pulFlags}
\end{DoxyParamCaption}
)}}
\label{group__mpu__api_gabb00a8e0bb445ff6f7276ebc5d0b4a73}
Gets the current settings for a specific region.


\begin{DoxyParams}{Parameters}
\item[{\em ulRegion}]is the region number to get. \item[{\em pulAddr}]points to storage for the base address of the region. \item[{\em pulFlags}]points to the attribute flags for the region.\end{DoxyParams}
This function retrieves the configuration of a specific region. The meanings and format of the parameters is the same as that of the \hyperlink{group__mpu__api_ga6b5ebdb618cd71191b07b3d3abcdfe4b}{MPURegionSet()} function.

This function can be used to save the configuration of a region for later use with the \hyperlink{group__mpu__api_ga6b5ebdb618cd71191b07b3d3abcdfe4b}{MPURegionSet()} function. The region's enable state will be preserved in the attributes that are saved.

\begin{DoxyReturn}{Returns}
None. 
\end{DoxyReturn}
\hypertarget{group__mpu__api_ga6b5ebdb618cd71191b07b3d3abcdfe4b}{
\index{mpu\_\-api@{mpu\_\-api}!MPURegionSet@{MPURegionSet}}
\index{MPURegionSet@{MPURegionSet}!mpu_api@{mpu\_\-api}}
\subsubsection[{MPURegionSet}]{\setlength{\rightskip}{0pt plus 5cm}void MPURegionSet (
\begin{DoxyParamCaption}
\item[{unsigned long}]{ ulRegion, }
\item[{unsigned long}]{ ulAddr, }
\item[{unsigned long}]{ ulFlags}
\end{DoxyParamCaption}
)}}
\label{group__mpu__api_ga6b5ebdb618cd71191b07b3d3abcdfe4b}
Sets up the access rules for a specific region.


\begin{DoxyParams}{Parameters}
\item[{\em ulRegion}]is the region number to set up. \item[{\em ulAddr}]is the base address of the region. It must be aligned according to the size of the region specified in ulFlags. \item[{\em ulFlags}]is a set of flags to define the attributes of the region.\end{DoxyParams}
This function sets up the protection rules for a region. The region has a base address and a set of attributes including the size, which must be a power of 2. The base address parameter, {\itshape ulAddr\/}, must be aligned according to the size.

The {\itshape ulFlags\/} parameter is the logical OR of all of the attributes of the region. It is a combination of choices for region size, execute permission, read/write permissions, disabled sub-\/regions, and a flag to determine if the region is enabled.

The size flag determines the size of a region, and must be one of the following:


\begin{DoxyItemize}
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-32B} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-64B} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-128B} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-256B} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-512B} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-1K} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-2K} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-4K} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-8K} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-16K} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-32K} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-64K} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-128K} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-256K} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-512K} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-1M} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-2M} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-4M} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-8M} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-16M} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-32M} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-64M} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-128M} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-256M} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-512M} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-1G} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-2G} 
\item {\bfseries MPU\_\-RGN\_\-SIZE\_\-4G} 
\end{DoxyItemize}

The execute permission flag must be one of the following:


\begin{DoxyItemize}
\item {\bfseries MPU\_\-RGN\_\-PERM\_\-EXEC} enables the region for execution of code
\item {\bfseries MPU\_\-RGN\_\-PERM\_\-NOEXEC} disables the region for execution of code
\end{DoxyItemize}

The read/write access permissions are applied separately for the privileged and user modes. The read/write access flags must be one of the following:


\begin{DoxyItemize}
\item {\bfseries MPU\_\-RGN\_\-PERM\_\-PRV\_\-NO\_\-USR\_\-NO} -\/ no access in privileged or user mode
\item {\bfseries MPU\_\-RGN\_\-PERM\_\-PRV\_\-RW\_\-USR\_\-NO} -\/ privileged read/write, user no access
\item {\bfseries MPU\_\-RGN\_\-PERM\_\-PRV\_\-RW\_\-USR\_\-RO} -\/ privileged read/write, user read-\/only
\item {\bfseries MPU\_\-RGN\_\-PERM\_\-PRV\_\-RW\_\-USR\_\-RW} -\/ privileged read/write, user read/write
\item {\bfseries MPU\_\-RGN\_\-PERM\_\-PRV\_\-RO\_\-USR\_\-NO} -\/ privileged read-\/only, user no access
\item {\bfseries MPU\_\-RGN\_\-PERM\_\-PRV\_\-RO\_\-USR\_\-RO} -\/ privileged read-\/only, user read-\/only
\end{DoxyItemize}

The region is automatically divided into 8 equally-\/sized sub-\/regions by the MPU. Sub-\/regions can only be used in regions of size 256 bytes or larger. Any of these 8 sub-\/regions can be disabled. This allows for creation of ``holes'' in a region which can be left open, or overlaid by another region with different attributes. Any of the 8 sub-\/regions can be disabled with a logical OR of any of the following flags:


\begin{DoxyItemize}
\item {\bfseries MPU\_\-SUB\_\-RGN\_\-DISABLE\_\-0} 
\item {\bfseries MPU\_\-SUB\_\-RGN\_\-DISABLE\_\-1} 
\item {\bfseries MPU\_\-SUB\_\-RGN\_\-DISABLE\_\-2} 
\item {\bfseries MPU\_\-SUB\_\-RGN\_\-DISABLE\_\-3} 
\item {\bfseries MPU\_\-SUB\_\-RGN\_\-DISABLE\_\-4} 
\item {\bfseries MPU\_\-SUB\_\-RGN\_\-DISABLE\_\-5} 
\item {\bfseries MPU\_\-SUB\_\-RGN\_\-DISABLE\_\-6} 
\item {\bfseries MPU\_\-SUB\_\-RGN\_\-DISABLE\_\-7} 
\end{DoxyItemize}

Finally, the region can be initially enabled or disabled with one of the following flags:


\begin{DoxyItemize}
\item {\bfseries MPU\_\-RGN\_\-ENABLE} 
\item {\bfseries MPU\_\-RGN\_\-DISABLE} 
\end{DoxyItemize}

As an example, to set a region with the following attributes: size of 32 KB, execution enabled, read-\/only for both privileged and user, one sub-\/region disabled, and initially enabled; the {\itshape ulFlags\/} parameter would have the following value:

{\ttfamily  (MPU\_\-RG\_\-SIZE\_\-32K $|$ MPU\_\-RGN\_\-PERM\_\-EXEC $|$ MPU\_\-RGN\_\-PERM\_\-PRV\_\-RO\_\-USR\_\-RO $|$ MPU\_\-SUB\_\-RGN\_\-DISABLE\_\-2 $|$ MPU\_\-RGN\_\-ENABLE) }

\begin{DoxyNote}{Note}
This function will write to multiple registers and is not protected from interrupts. It is possible that an interrupt which accesses a region may occur while that region is in the process of being changed. The safest way to handle this is to disable a region before changing it. Refer to the discussion of this in the API Detailed Description section.
\end{DoxyNote}
\begin{DoxyReturn}{Returns}
None. 
\end{DoxyReturn}
